// var baseURL = "http://api.bdyxlive.com/index.php/api/Versions";
var URL = 'http://bdyx.oss-cn-beijing.aliyuncs.com' //图片地址
var imgURL = 'http://zhqm.oss-cn-beijing.aliyuncs.com/'
var baseURL = 'http://39.107.45.63:8088' //测试环境地址
// var baseURL = 'http://admin.huirzq.com' //正式环境地址
$(function () {
  $('body').click(function () {
    if ($('.location-container').is(':visible')) {
      $('.location-container').hide()
    }
  })
})
function redirectToMobile() {
  if (window.location.toString().indexOf('pref=padindex') != -1) {
  } else {
    if (
      /AppleWebKit.*Mobile/i.test(navigator.userAgent) ||
      /MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(
        navigator.userAgent
      )
    ) {
      if (window.location.href.indexOf('?mobile') < 0) {
        try {
          if (
            /Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(
              navigator.userAgent
            )
          ) {
            // window.location.href = 'http://m.chmqlive.com'
            var pathname = location.pathname.split('/')[1].split('.')[0]
            if (pathname == 'getReward') {
              window.location.href = 'http://m.huirzq.com/reward'
            }
          } else if (/iPad/i.test(navigator.userAgent)) {
          } else {
          }
        } catch (e) {}
      }
    }
  }
}
function changePage(num) {
  var params = getURLParams()
  params.page = num
  var temp = makeURLParams(params)
  var targetURL = location.pathname + temp
  go(targetURL)
}
function getURLParams() {
  var URL = location.search
  var result = {}
  var params = ''
  if (URL) {
    params = URL.split('?')[1].split('&&')
  }
  for (key in params) {
    var name = params[key].split('=')[0]
    var value = params[key].split('=')[1]
    result[name] = value
  }
  return result
}
function makeURLParams(params) {
  var targetParams = '?'
  for (key in params) {
    if (params[key]) {
      targetParams += key + '=' + params[key] + '&&'
    }
  }
  if (targetParams !== '?') {
    return targetParams.substring(0, targetParams.length - 2)
  } else {
    return ''
  }
}
function initCity(key, page, type) {
  $.ajax({
    url:
      baseURL + '/api/investProm/cityList?city_type=' + key + '&&page=' + page,
    type: 'GET',
    success: function (res) {
      var wholeCity = res.data.wholeCity
      var data = res.data.cityInfo || res.data.hotCity
      var city_id = sessionStorage.getItem('city_id')
      // 头部切换城市弹框传值
      pageNum = res.data.totalPage
      $('.next').removeClass('not-allowed')
      $('.back').removeClass('not-allowed')
      if (page === 1) {
        $('.back').addClass('not-allowed')
        if (pageNum === 1) {
          $('.next').addClass('not-allowed')
        }
      } else if (page === +pageNum) {
        $('.next').addClass('not-allowed')
      }
      $('.city-bottom').css('display', 'block')
      $('.city-remove').remove()
      if (type !== 'hot') {
        for (key in data) {
          if (key !== 'totalPage' && data[key].length > 0) {
            $('.citys').append(
              '<div class="city-remove city-' + key + '" ></div>'
            )
            $('.city-' + key).append(
              '<div class="city-key">' +
                key +
                ' </div><div class="city-remove city-common city-item-container-' +
                key +
                '" ></div>'
            )
            for (key2 in data[key]) {
              var item = data[key][key2]
              $('.city-item-container-' + key).append(
                '<div class="citys-item" id="' +
                  item.postal_code +
                  '">' +
                  item.city_name +
                  ' </div>'
              )
            }
          }
        }
      } else {
        if (!sessionStorage.getItem('city_name')) {
          var flag = false
          // 判断当前定位城市是否为已开放城市
          sessionStorage.setItem('city_id', '')
          sessionStorage.setItem('city_name', '全国')
          for (var i in wholeCity) {
            var item = wholeCity[i]
            if (item.postal_code === +city_id) {
              sessionStorage.setItem('city_name', item.city_name)
              sessionStorage.setItem('city_id', item.postal_code)
              $('#location').html(item.city_name)
              flag = true
              break
            }
          }
          if (!flag) {
            $('#location').html('全国')
          }
        }
        $('.citys-item').remove()
        $('.city-bottom').css('display', 'none')
        for (let key in data) {
          $('.citys').append(
            '<div class="citys-item" id="' +
              data[key].postal_code +
              '">' +
              data[key].city_name +
              ' </div>'
          )
        }
      }
      $('.citys-item').click(onCityItemClick)
    },
    error: function (err) {
      //失败回调函数
    },
  })
}
function onCityItemClick(e) {
  var city_id = $(this)[0].id
  var city_name = $(this).html().replace(/\s*$/g, '')
  var params = getURLParams()
  // params.city_id = city_id
  // params.city_name = city_name
  sessionStorage.setItem('city_id', city_id)
  sessionStorage.setItem('city_name', city_name)
  go('./')
}
function initTopCarousel(carouselData, parent) {
  var carouselLi = ''
  var carouselPointLi = ''
  if (carouselData) {
    for (var index in carouselData) {
      carouselLi += initCarouselLi(carouselData[index], index)
      if (carouselData.length > 1) {
        carouselPointLi +=
          '<li ' +
          (+index === 0 ? 'class="pb-this"' : '') +
          '>0' +
          (+index + 1) +
          '</li>'
      }
    }
    // carouselPointLi += '<img src="./picture/image/top_line.png" />'
    parent.find('#banner-1').append(carouselLi)
    parent.find('#banner-1-point').append(carouselPointLi)
    parent.find('.pb-arrow').remove()
    if (carouselData.length > 1) {
      carousel(
        parent.find('.carousel'), //必选， 要轮播模块(id/class/tagname均可)，必须为jQuery元素
        {
          type: 'leftright', //可选，默认左右(leftright) - 'leftright' / 'updown' / 'fade' (左右/上下/渐隐渐现)
          arrowtype: 'move', //可选，默认一直显示 - 'move' / 'none'	(鼠标移上显示 / 不显示 )
          autoplay: true, //可选，默认true - true / false (开启轮播/关闭轮播)
          time: 5000, //可选，默认3000
        }
      )
    }
  }
}
//生成顶部轮播图liDOM
function initCarouselLi(data, index) {
  return (
    '<li  ' +
    (index == 0 ? 'class="pb-this"' : '') +
    '>' +
    '<a class="banner-a" style="width:100%" rel="nofollow" href="' +
    data.url +
    '" id="' +
    data.poster_id +
    '' +
    (data.url == '#' ? '" target=""' : '" target="_blank"') +
    '>' +
    '<img' +
    ' src="' +
    (data.images.indexOf('image') > 0 ? data.images : URL + data.images) +
    '"data-adaptive-background="1"' +
    'alt="汇融名企轮播广告' +
    index +
    '"' +
    '/>' +
    '</a>' +
    '</li>'
  )
}
function getDate(timestamp, type) {
  var d = new Date(timestamp * 1000) //根据时间戳生成的时间对象
  var date = []
  date.push(
    d.getFullYear() +
      '-' +
      (d.getMonth() + 1 < 10 ? '0' + (d.getMonth() + 1) : d.getMonth() + 1) +
      '-' +
      (d.getDate() < 10 ? '0' + d.getDate() : d.getDate())
  )
  date.push(
    d.getFullYear() + '年' + (d.getMonth() + 1) + '月' + d.getDate() + '日'
  )
  date.push(d.getFullYear() + '年' + (d.getMonth() + 1) + '月')
  date.push(d.getMonth() + 1 + '-' + d.getDate())
  return date[type || 0]
}
function go(URL, params) {
  window.location.href = URL + (params || '')
}

function stayMidIndex() {
  var width = $(window).width()
  if (width > 1500) {
    var left = (width - 1500) / 2
    for (var i = 0; i < $('.wrapper').length; i++) {
      $('.wrapper')[i].style.left = left + 'px'
    }
    $('.location-container').css('left', left + 390)
    $('#menu').css('left', left)
    $('.content-banner').css('right', left)
    $('body').css('width', 'auto')
  } else {
    for (var i = 0; i < $('.wrapper').length; i++) {
      $('.wrapper')[i].style.left = ''
    }
    $('.location-container').css('left', 390)
    $('#menu').css('left', 210)
    $('.content-banner').css('right', 210)
    $('body').css('width', 1920)
  }
  if (width > 1920) {
    var bannerLeft = (width - 1920) / 2
    $('.header-banner').css('left', bannerLeft)
  } else {
    $('.header-banner').css('left', 0)
  }
  window.onresize = function () {
    stayMidIndex()
  }
}
function stayMid() {
  var width = $(window).width()
  if (width > 1500) {
    var left = (width - 1500) / 2
    for (var i = 0; i < $('.wrapper').length; i++) {
      $('.wrapper')[i].style.left = left + 'px'
    }
    $('body').css('width', 'auto')
  } else {
    for (var i = 0; i < $('.wrapper').length; i++) {
      $('.wrapper')[i].style.left = ''
    }
    $('body').css('width', 1920)
  }
  if (width > 1920) {
    var bannerLeft = (width - 1920) / 2
    $('.header-banner').css('left', bannerLeft)
  } else {
    $('.header-banner').css('left', 0)
  }
  window.onresize = function () {
    stayMid()
  }
}
function transformToFixed() {
  setTimeout(function () {
    var width = document.documentElement.getBoundingClientRect().width
    var rate = (width / 1920).toFixed(3)
    if (rate <= 0.99) {
      var css = {
        transform: 'scale(' + rate + ')',
        'transform-origin': '0 0 0',
        transition: '0.5s',
      }
      $('body').css(css)
      var height = $('body').height() * rate + 'px'
      $('body').css('max-height', height)
      window.onresize = function () {
        transformToFixed()
      }
    } else if (rate >= 1.01) {
      stayMid()
    }
  }, 400)
  // window.onresize = function() {
  //   transformToFixed()
  // }
}

function addMessage(data, type) {
  $('.m-message').remove()
  var message = new MyMessage.message({
    /*默认参数，下面为默认项*/
    iconFontSize: '20px', //图标大小,默认为20px
    messageFontSize: '12px', //信息字体大小,默认为12px
    showTime: 4000, //消失时间,默认为3000
    align: 'center', //显示的位置类型center,right,left
    positions: {
      //放置信息距离周边的距离,默认为10px
      top: 20 + 'px',
      bottom: '10px',
      right: '10px',
      left: '10px',
    },
    message: '这是一条消息', //消息内容,默认为"这是一条消息"
    type: 'success', //消息的类型，还有success,error,warning等，默认为normal
  })
  message.add(data, type)
}
function initPoster(data) {
  for (key in data) {
    var temp = $('#poster-' + data[key].id)
    temp[0].href = data[key].url
    temp.find('img')[0].src = data[key].images
    temp[0].id = data[key].poster_id
  }
}
function hasCity(city_id, city_name) {
  if (!sessionStorage.getItem('city_id')) {
    var city_name = returnCitySN['cname'].split('省')[1]
    var city_id = returnCitySN['cid']
    sessionStorage.setItem('city_id', city_id)
    sessionStorage.setItem('city_name', city_name)
  }
}
function onShow(time) {
  $('body').css('overflow', 'hidden')
  setTimeout(function () {
    $('.board').hide()
    $('body').css('overflow', 'auto')
  }, time)
}
// $.ajax({
//   url: 'http://api.bdyxlive.com/api/home/index?city_id=' + cityId,
//   type: 'GET',
//   timeout: 10000,
//   success: function(res) {
//     init(res.data)
//   },
//   error: function(err) {
//     //失败回调函数
//   },
//   complete: function(XMLHttpRequest, status) {
//     //当请求完成时调用函数
//     if (status == 'timeout') {
//       //status == 'timeout'意为超时,status的可能取值：success,notmodified,nocontent,error,timeout,abort,parsererror
//       location.replace('404.html')
//     }
//   }
// })
function initLoading(target) {
  var opts = {
    lines: 9, // The number of lines to draw

    length: 0, // The length of each line

    width: 10, // The line thickness

    radius: 15, // The radius of the inner circle

    corners: 1, // Corner roundness (0..1)

    rotate: 0, // The rotation offset

    color: '#000', // #rgb or #rrggbb

    speed: 1, // Rounds per second

    trail: 60, // Afterglow percentage

    shadow: false, // Whether to render a shadow

    hwaccel: false, // Whether to use hardware acceleration

    className: 'spinner', // The CSS class to assign to the spinner

    zIndex: 2e9, // The z-index (defaults to 2000000000)

    top: 'auto', // Top position relative to parent in px

    left: 'auto', // Left position relative to parent in px
  }

  // var target = document.getElementById('foo');

  var spinner = new Spinner(opts).spin(target)
}
function MultiTextOverflow(el) {
  el.each(function (i) {
    var divH = $(this).height()
    var divW = $(this).width()
    var $span = $('span', $(this)).eq(0)

    while ($span.outerHeight() > divH) {
      $span.text(
        $span.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, '...')
      )
    }
    // if (divH === $span.outerHeight()) {
    //   for (var i = 0; i < 6; i++) {
    //     $span.text(
    //       $span.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, '...')
    //     )
    //   }
    // }
  })
}
function MultiTextOverflowForRankingItem(el) {
  el.each(function (i) {
    var divH = $(this).height()
    var divW = $(this).width()
    var $span = $('span', $(this)).eq(0)

    while ($span.outerHeight() > divH) {
      $span.text(
        $span.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, '...')
      )
    }
    for (var i = 0; i < 2; i++) {
      $span.text(
        $span.text().replace(/(\s)*([a-zA-Z0-9]+|\W)(\.\.\.)?$/, '...')
      )
    }
  })
}
// 提示框
// function promptMessage(msg, type) {
//   $.message({
//     message: msg,
//     type: type
//   })
// }

// 两侧悬浮全民星选 (首页、火热招商、关于我们页面)
// 因业务需要注释掉两侧悬浮渐入渐出效果
// showSuspensionLeft = true
// showSuspensionRight = true
// var targetName = location.pathname.split('/')[1].split('.')[0] || 'index'
// var scrollNum
// console.log($('.header-top-banner').is(':visible'))
// if (targetName == 'aboutUs') {
//   scrollNum = 840
// } else {
//   scrollNum = 630
// }
// $(window).scroll(function () {
//变量scrollTop是滚动条滚动时，距离顶部的距离
// var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
//滚动条到底部的条件
// if (
//   scrollTop >=
//     ($('.header-top-banner').is(':visible') ? scrollNum + 180 : scrollNum) &&
//   (showSuspensionLeft || showSuspensionRight)
// ) {
// $('.brand-star').show()
// } else {
//   $('.brand-star').hide()
// }
// })
setTimeout(function () {
  $('.brand-star').show()
}, 500)
$('#brand-left-close').click(function () {
  $('.brand-star-left').hide()
  // showSuspensionLeft = false
})
$('#brand-right-close').click(function () {
  $('.brand-star-right').hide()
  // showSuspensionRight = false
})
// cnzz统计
var statistical = $("#statistical")
statistical.append(
  unescape(
    "%3Cspan id='cnzz_stat_icon_1278968664'%3E%3C/span%3E%3Cscript src='https://s4.cnzz.com/z_stat.php%3Fid%3D1278968664%26show%3Dpic' type='text/javascript'%3E%3C/script%3E"
  )
)
